var vm_customyue = new Vue({
    el: "#customyue",
    data: {
        deptid: $("#deptid").val(),		// 单位ID

        tuikuanlist: [],// 退款list
        tuikuanid: '',//退款id

        yue: {
            yue:0,
            zhiliu:0,
            daifa:0
        }, //余额
        tuikuanAdd: {},//退款

        pageindex: 1,		// 查询分页初始化页
        pagesize: 10,		// 查询分页初始化页面大小
        pageCount: 0,		// 总页数
        recordCount: 0,	// 总记录数
        targetpage: '', 	// 目标页

    },
    created: function () {
        var _this = this;
        _this.bindYue();
        _this.bindTuikuanList();

    },
    watch: {
        //监控分页情况，刷新列表
        pageindex: function () {
            this.bindTuikuanList();
        },
        'tuikuanAdd.daifa': function () {
            if (!/^[1-9]\d*$/.test(this.tuikuanAdd.daifa))this.tuikuanAdd.daifa=0
            if(parseInt(this.tuikuanAdd.daifa)>parseInt(this.yue.daifa))this.tuikuanAdd.daifa=this.yue.daifa
            this.tuikuanAdd.yue = parseInt(this.tuikuanAdd.daifa) + this.tuikuanAdd.zhiliu
        },

        pagesize: function () {
            //
            this.bindTuikuanList();
        },
    },
    methods: {
        bindYue: function () {
            var _this = this;
            $.post('/system/yue/yue', {
                deptid: _this.deptid,
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == 1) {
                        if(ppData.resultContent!=null)
                        _this.yue = ppData.resultContent;
                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },

        // 根据单位ID查询专家变动申请信息
        bindTuikuanList: function () {
            var _this = this;
            $.post('/system/tuikuan/tuikuanlist', {
                deptid: _this.deptid,
                pageindex: _this.pageindex,
                pagesize: _this.pagesize,
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.tuikuanlist = data.tuikuanlist;
                        var pageInfo = data.PageInfo;
                        _this.pageindex = pageInfo.pageIndex;
                        _this.pageCount = pageInfo.pageCount;
                        _this.recordCount = pageInfo.recordCount;
                        _this.targetpage = '';
                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },

        toTuikuan: function () {
            var _this = this
            _this.tuikuanAdd = Object.assign({},_this.yue);
            $("#myModalLabel").html("提交退款");
            $("#tuikuanModal").modal();

        },
        refresh:function(){
            var _this = this;

            _this.bindYue();
            _this.bindTuikuanList();
        },
        //退款
        tuikuan: function () {
            var _this = this;
            $.post('/system/tuikuan/zhidingtuikuanjihua', {
                    deptId: _this.deptid,
                    daifa: _this.tuikuanAdd.daifa,
                    zhiliu: _this.tuikuanAdd.zhiliu,
                    tuituanyuanyin:_this.tuikuanAdd.tuituanyuanyin
                }, function (ppData) {
                    if (ppData != null) {
                        if (ppData.result == 1) {
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "提交退款成功!",
                            });
                            _this.refresh();
                            $("#tuikuanModal").modal('hide');
                        } else {
                            layer.alert(ppData.message);
                        }
                    }
                }, "json");

        },

        //检查项目数据
        checkInputData: function () {
            if (!$.trim(this.biandong.zhuanjiaid)) {
                layer.alert("请选择变动的专家！");
                return false;
            }

            if (!$.trim(this.biandong.biandongleixing)) {
                layer.alert("请选择变动的类型");
                return false;
            }

            return true;
        },

        //首页
        firstPage: function () {
            this.pageindex = 1;
        },
        //尾页
        lastPage: function () {
            this.pageindex = this.pageCount;
        },
        //上一页
        prePage: function () {
            var prePage = ((this.pageindex - 1) <= 0) ? 1 : (this.pageindex - 1);
            this.pageindex = prePage;
        },
        //下一页
        nextPage: function () {
            var nextPage = ((this.pageindex + 1) >= this.pageCount) ? this.pageCount : (this.pageindex + 1);
            this.pageindex = nextPage;
        },
        //跳到目标页
        targetPage: function () {
            if (this.targetpage != '' && this.targetpage <= this.pageCount && this.targetpage > 0) {
                this.pageindex = this.targetpage;
                this.targetpage = '';
            }
        },

    },
})